﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac.Configuration;
using Autofac;
using System.Linq.Expressions;
using System.Reflection;

namespace AutofacDemo
{
    /// <summary>
    /// DB Operate Interface
    /// </summary>
    public interface IRepository<T>
    {
        IEnumerable<T> Get();
    }
    /// <summary>
    /// 对SQL数据源操作
    /// </summary>
    public class SqlRepository<T> : IRepository<T>
    {

        #region IRepository<T> 成员

        public IEnumerable<T> Get()
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    /// <summary>
    /// 数据源基类
    /// </summary>
    public class DBBase<T> where T : class
    {
        private IRepository<T> _iRepository;
        public DBBase(IRepository<T> iRepository)
        {
            _iRepository = iRepository;
        }
        public IEnumerable<T> Search()
        {
            //通过配置文件，配合Register方法来创建对象
            return _iRepository.Get();
        }
    }

    public class ioc
    {
        public void Register(ContainerBuilder builder)
        {
            //services
            builder.RegisterGeneric(typeof(SqlRepository<>)).As(typeof(IRepository<>)).InstancePerDependency();
        }
    }
    class user { }
    class orderable<T>
    {
        IEnumerable<T> _query;
        public orderable(IEnumerable<T> query)
        {
            _query = query;
        }
        public orderable<T> Asc<TKey>(Expression<Func<T, TKey>> keySelector)
        {
            _query = _query.AsQueryable().OrderBy(keySelector);
            return this;
        }
        public IEnumerable<T> Queryable { get { return _query; } }
        public orderable<T> testzzl() { return this; }
    }
    class Program
    {
        static IEnumerable<T> orderby<T>(IEnumerable<T> query, Action<orderable<T>> order)
        {
            var orderable = new orderable<T>(query);
            order(orderable);
            return orderable.Queryable;
        }
        static void Main(string[] args)
        {
            int[] arr = { 1, 3, 2, 4 };

            orderby<int>(arr, i => { i.Asc(j => j); }).ToList()
                .ForEach(i => Console.WriteLine(i));



            var builder = new ContainerBuilder();
            ioc dr = new ioc();
            Console.ReadKey();
        }
    }
}
